package nfa_generator;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

public class NFANode {
	private String name;
	private String token;
	private Map<String, List<NFANode>> transitions;
	
	/**
	 * Constructor for NFANode, initializes everything to null.
	 */
	public NFANode() {
		this.setName("");
		transitions = new HashMap<String, List<NFANode>>();
	}

	/**
	 * Getter for node name.
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * Setter for node name.
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Getter for token type.
	 * @return
	 */
	public String getToken() {
		return token;
	}
	
	/**
	 * Setter for token type.
	 */
	public void setToken(String token) {
		this.token = token;
	}
	
	/**
	 * Takes in an input string and a destination node and adds the state transition to the current hashmap of transitions.
	 * @param input
	 * @param destination
	 */
	public void addTransition(String input, NFANode destination) {
		List<NFANode> destinations;
		if(!transitions.containsKey(input)) {
			destinations = new ArrayList<NFANode>();
			destinations.add(destination);
			transitions.put(input, destinations);
		}
		else {
			destinations = transitions.get(input);
			destinations.add(destination);
			transitions.put(input, destinations);
		}
	}
	
	/**
	 * Getter for node transitions based on input.
	 * @param input
	 * @return
	 */
	public List<NFANode> getTransitions(String input) {
		return transitions.get(input);
	}
}